/**
 * 用于生成slidbar
 * Created by Administrator on 2016/1/27.
 */

(function ($) {
    "use strict";
    moment.locale("zh-cn");
    var mainContent = $("#page-content");
    var selectId, table, selectRow, detailTable, lastLoadFxid;

    /**
     * 初始化表格
     */
    function aceSwitch(cellvalue, options, cell) {
        setTimeout(function () {
            $(cell).find('input[type=checkbox]')
                .addClass('ace ace-switch ace-switch-5')
                .after('<span class="lbl"></span>');
        }, 0);
    }

    function updatePagerIcons(table) {
        var replacement =
        {
            'ui-icon-seek-first': 'ace-icon fa fa-angle-double-left bigger-140',
            'ui-icon-seek-prev': 'ace-icon fa fa-angle-left bigger-140',
            'ui-icon-seek-next': 'ace-icon fa fa-angle-right bigger-140',
            'ui-icon-seek-end': 'ace-icon fa fa-angle-double-right bigger-140'
        };
        $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function () {
            var icon = $(this);
            var $class = $.trim(icon.attr('class').replace('ui-icon', ''));

            if ($class in replacement) icon.attr('class', 'ui-icon ' + replacement[$class]);
        })
    }

    /**
     * 初始化日期选择控件
     */
    var initDatepicker = function () {
        $('.date-picker').datepicker({
                startView: 1,
                minViewMode: 1,
                maxViewMode: 1,
                autoclose: true,
                language: 'zh-CN',
                todayHighlight: true
            })
            //show datepicker when clicking on the icon
            .next().on(ace.click_event, function () {
            $(this).prev().focus();
        });
    };
    /**
     * 初始化风控点
     */
    var initFxfkjz = function () {
        $.request(
            $.router.server + "findAllFxfkjz",
            {
                "type": "post",
                "callback": function (data) {
                    for (var i in data) {
                        var item = data[i];
                        var tmp = '<a href="#" data-id="'+item.id+'" class="dynamic-btn btn btn-white btn-info btn-bold col-sm-1">' +
                                '<i class="ace-icon fa fa-cog bigger-120 blue"></i>' +
                                item.id +
                                '</a>';
                        $('#fxBtnLst').append(tmp);
                    }
                }
            }
        )
    };
    var doDynamic = function(){
        var fxid = $(this).data("id");
        var cycle = $('#checkDate').val();
        $.request(
            $.router.server + "dynamic/toDataMartDo",
            {
                "type": "post",
                "data":{
                    fxid:fxid,
                    cycle:cycle
                },
                "callback": function (data) {
                }
            }
        )
    };
    var pageReady = function () {
        initDatepicker();
        initFxfkjz();
    };
    mainContent.on("pageshow.0306", function () {
        if (mainContent.find("[data-page=dynamic]").length > 0) {
            pageReady();
        }
    });
    $(document).on("click.dynamic-btn",".dynamic-btn",doDynamic);
})(jQuery);
